import { getOrderAndNumber, isEmpty } from '@/utils/index.js';

export default {
	methods: {
		scanQrCode() {
			// #ifdef H5
			return uni.$u.toast('暂不支持扫码功能');
			// #endif
			
			uni.scanCode({
				success: res => {
					const result = getOrderAndNumber(decodeURIComponent(res.result));
					if (isEmpty(result)) {
						return uni.$u.toast('无法识别');
					}
					// 通过桩的编号获取电站id
					this.$http_api.getPileId({ terminalId: result.terminalId, gunCode: result.gunCode }).then(data => {
						uni.navigateTo({
							url: `/pages/scan/step2?id=${data.stationId}&terminalId=${data.id}`
						})
					});
				},
				fail: error => {
					uni.$u.toast('识别失败');
				}
			});
		}
	}
}